<?php
// +----------------------------------------------------------------------
// | JSHOP [ 小程序商城 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://jihainet.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: tianyu <tianyu@jihainet.com>
// +----------------------------------------------------------------------

namespace app\manage\controller;
use app\common\controller\Manage;
use think\facade\Request;
use app\common\model\Link as linkModel;

class Link  extends Manage
{



    public function index ()
    {
        if (Request::isAjax())
        {
            $linkModel = new linkModel();
            return $linkModel->tableData(input('param.'));
        }

        return $this->fetch();

    }




    public function add ()
    {
        $this->view->engine->layout(false);
        if (Request::isPost()) {
            $linkModel = new linkModel();
            return $linkModel->addData(input('param.'));
        }
        return $this->fetch();
    }



    public function edit ()
    {
        $this->view->engine->layout(false);

        $linkModel = new linkModel();
        if (Request::isPost())
        {
            return $linkModel->editData(input('param.'));
        }

        $info = $linkModel->getInfo(input('param.id/d'));

        return $this->fetch('', ['info' => $info['data']]);
    }



    /**
     * 删除
     */
    public function del() {
        $result = [
            'status' => false,
            'msg' => '删除失败',
            'data' => []
        ];

        $linkModel = new linkModel();
        $id = input('param.id/d');

        if (!$id) {
            $result['msg'] = '缺少参数id';
            return $result;
        }

        if ($linkModel->where('id', $id)->delete()){
            $result['status'] = true;
            $result['msg'] = '删除成功';
        }

        return $result;

    }
}